<?php
namespace App\Console\Commands;

use App\Models\Collecter\MiniCollecterCollected;
use App\Wen\Utils\CollecterUtils;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class CollecterPublishPostsJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public $tries = 1;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }
    /**
     * 确定任务应该超时的时间
     *
     * @return \DateTime
     */
    public function retryUntil()
    {
        return now()->addMinutes(10);
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try{
            $collecteds = MiniCollecterCollected::where('status', 1)->orderBy(DB::raw('RAND()'))->limit(1)->get();
            if($collecteds){
                foreach ($collecteds as $collected){
                    CollecterUtils::publish($collected->id);
                }
            }
        }catch (\Exception $e){
            _logger_(__file__, __line__, $e->getMessage());
        }
    }
}
